<!--
* description: 备件出入库明细查询
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      v-if="initTemplate"
      ref="multipleTable"
      :dynamicButtons="tableButtons"
      :dynamicComponents="tableComponents"
      :dynamicApiConfig="apiConfig"
      :dynamicTableCols="tableCols"
      :dynamicFormFields="formField"
      :dynamicUnFormFields="unFormField"
      :dynamicIsShowSelect="false"
      :dynamicIsColumnDrop="true"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import { wmsApis } from "@/api/wms/inStock/api";
import OneTableTemplate from "@/components/wms/templates/oneTable";
import request from "@/utils/request";
import store from "@/store";
export default {
  name: "partInAndOutQuery",
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],
  components: {
    OneTableTemplate
  },
  watch: {
    $route(val) {
      if (
        this.formField.pageId !== "" &&
        this.$route.query.pageId !== undefined &&
        this.$route.query.pageId !== this.formField.pageId
      ) {
        this.formField.pageId = this.$route.query.pageId;
        this.formField.pageName = this.$route.query.pageName;
        this.queryTable();
      }
    }
  },
  created() {
    if (this.$route.query != null) {
      // 判断传入query参数，初始化数据
      if (this.$route.query.pageId != null && this.$route.query.pageId !== "") {
        this.formField.pageId = this.$route.query.pageId;
        this.formField.pageName = this.$route.query.pageName;
      }
    }
  },
  mounted() {
    this.querySelect();
  },
  data() {
    return {
      // 网格查询API配置对象
      apiConfig: wmsApis.queryPartInAndOut,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.queryTable(),
          name: "search",
          position: "right",
          text: "查询" //"查询"
        },
        {
          compKey: "btnKey2",
          type: "",
          size: "small",
          name: "reset",
          position: "right",
          clickEvent: () => this.reset(),
          text: "重置"
        },
        // {
        //   compKey: "btnKey3",
        //   type: "",
        //   size: "small",
        //   clickEvent: () => this.export(),
        //   name: "export",
        //   position: "right",
        //   text: "导出" //"导出"
        // }
      ],
      // 动态组件-查询条件
      tableComponents: [
        {
          compKey: "compKey1",
          labelName: "到货仓库",
          codeField: "WAREHOUSE_IDS",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          isMust: true,
          isMul: true,
          options: []
        },
        {
          compKey: "compKey2",
          labelName: "类型",
          codeField: "TYPE",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          isMust: true,
          isMul: false,
          options: [
            {
              label: "出库",
              value: "出库"
            },
            {
              label: "入库",
              value: "入库"
            }
          ],
          changed: val => {
            this.formField.STORAGE_TYPE_NAME = "";
            this.tableComponents[2].options = [];
            if (!val) {
              return;
            }
            request({
              url: "/mp/wm/vl/warehouse/instorage/queryInOutStorage.do",
              method: "post",
              data: {
                TYPE: val
              }
            }).then(res => {
              if (res.listRow && res.listRow.length > 0) {
                res.listRow.map(item => {
                  this.tableComponents[2].options.push({
                    label: item.STORAGE_TYPE_NAME,
                    value: item.STORAGE_TYPE_NAME
                  });
                });
              }
            });
          }
        },
        {
          compKey: "compKey3",
          labelName: "出入库类别",
          codeField: "STORAGE_TYPE_NAME",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          isMust: true,
          isMul: false,
          options: []
        },
        {
          compKey: "compKey4",
          labelName: "备件编号",
          codeField: "PART_NO",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true
        },
        {
          compKey: "compKey5",
          labelName: "出入库时间",
          codeField: "LAST_UPDATED_DATE_START",
          component: () => import("@/components/wms/datePicker/andtDatePicker"),
          type: "date",
          isMust: true
        },
        {
          compKey: "compKey6",
          labelName: "出入库单号",
          codeField: "STORAGE_CODE",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true
        },
      ],
      // 动态生成网格列
      tableCols: [
        {
          prop: "LAST_UPDATED_DATE",
          label: "出入库时间",
          align: "center",
          width: "150"
        },
        {
          prop: "TYPE",
          label: "类型",
          align: "center",
          width: "100"
        },
        {
          prop: "STORAGE_TYPE_NAME",
          label: "出入库类别",
          align: "center",
          width: "100"
        },
        {
          prop: "PART_NO",
          label: "备件编号",
          align: "center",
          width: "100"
        },
        {
          prop: "PART_NAME",
          label: "备件名称",
          align: "center",
          width: "100"
        },
        //   {
        //   prop: "POINT_PRICE_TAX",
        //   label: " 网点价（含税）",
        //   align: "center",
        //   width: "100"
        // }, 
        //  {
        //   prop: "POINT_PRICE_NOT_TAX",
        //   label: "网点价（不含税）",
        //   align: "center",
        //   width: "100"
        // }, 
         {
          prop: "PART_CUBAGE",
          label: "备件体积显示",
          align: "center",
          width: "100"
        },
        {
          prop: "PART_NAME_EN",
          label: "备件英文名称",
          align: "center",
          width: "100"
        },
        {
          prop: "QTY",
          label: "出入库数量",
          align: "center",
          width: "100"
        },
        {
          prop: "STORAGE_CODE",
          label: "出入库单号",
          align: "center",
          width: "200"
        },
        {
          prop: "SUPPLIER_CODE",
          label: "来源/去向编号",
          align: "center",
          width: "100"
        },
        {
          prop: "PARTNER_SHORT_NAME",
          label: "来源/去向名称",
          align: "center",
          width: "100"
        },
        {
          prop: "ORDER_CODE",
          label: "订单号",
          align: "center",
          width: "150"
        },
        {
          prop: "ORDER_LINE_CODE",
          label: "订单行号",
          align: "center",
          width: "100"
        },
        {
          prop: "WAREHOUSE_NAME",
          label: "操作仓库",
          align: "center",
          width: "100"
        },
        {
          prop: "EMP_NAME",
          label: "操作人",
          align: "center",
          width: "150"
        }
      ],
      //表单查询数据
      formField: {
        WAREHOUSE_IDS: "",
        PART_NO: "",
        TYPE: "",
        STORAGE_TYPE_NAME: "",
        LAST_UPDATED_DATE_START: "",
        WAREHOUSE_IDS_NEW: "",
        STORAGE_CODE:""
      },
      unFormField: {},
      // 控制初始化页面
      initTemplate: false
    };
  },
  methods: {
    querySelect() {
      // 加载遮罩  暂不使用
      // store.dispatch("app/loading", true);
      request({
        url: "/mp/wm/vl/basedata/warehouseuser/queryUserByWHBox.do",
        method: "post",
        data: {
          IS_ENABLE: "1"
        }
      }).then(res => {
        if (res.listRow && res.listRow.length > 0) {
          res.listRow.map(item => {
            this.formField.WAREHOUSE_IDS_NEW += item.WAREHOUSE_ID + ",";
            this.tableComponents[0].options.push({
              label: item.WAREHOUSE_NAME,
              value: item.WAREHOUSE_ID
            });
          });
          this.formField.WAREHOUSE_IDS_NEW = this.formField.WAREHOUSE_IDS_NEW.substr(
            0,
            this.formField.WAREHOUSE_IDS_NEW.length - 1
          );
          this.formField.WAREHOUSE_IDS = res.listRow[0].WAREHOUSE_ID;
        }
        this.initTemplate = true;
        this.$nextTick(() => {
          this.queryTable();
        });
      });
    },
    // export() {
    //   const exportLoading = this.$loading({
    //     lock: true,
    //     text: "正在导出...",
    //     // spinner: "el-icon-loading",
    //     background: "rgba(0, 0, 0, 0.7)",
    //     fullscreen: true
    //   });
    //   request({
    //     url: "/mp/wm/vl/warehouse/instorage/exportPartInAndOut.do",
    //     method: "post",
    //     headers: {
    //       "Cache-Control": "no-cache, no-store,max-age=0, must-revalidate",
    //       Pragma: "no-cache",
    //       Expires: "0",
    //       "Content-Type": "application/json;charset=UTF-8"
    //     },
    //     responseType: "blob",
    //     data: this.formField
    //   })
    //     .then(response => {
    //       exportLoading.close();
    //       let blob = new Blob([response], { type: "application/vnd.ms-excel" }); // 这里表示xmlx类型
    //       let downloadElement = document.createElement("a");
    //       let href = window.URL.createObjectURL(blob); // 创建下载的链接
    //       downloadElement.href = href;
    //       downloadElement.download = "备件出入库明细查询导出.xls"; // 下载后文件名
    //       document.body.appendChild(downloadElement);
    //       downloadElement.click(); // 点击下载
    //       document.body.removeChild(downloadElement); // 下载完成移除元素
    //       window.URL.revokeObjectURL(href); // 释放掉blob对象
    //     })
    //     .catch(err => {
    //       exportLoading.close();
    //       console.log(err);
    //     });
    // }
  }
};
</script>
